/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: StatusPanel.java 567 2010-07-25 20:55:57Z Harry $
 *   $LastChangedDate: 2010-07-25 20:55:57 +0000 (Sun, 25 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.ui.component;

import battlefield.resource.Graphics;
import battlefield.entity.Player;
import java.awt.Color;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Kent
 */
public class StatusPanel extends JPanel {

    ImageIcon backImage;
    Image image;
    int unitsAlive, unitsDestroyed;
    int opponentAlive, opponentDestroyed;
    int goldAmt;
    private JLabel statusBar;
    private JLabel timer;

    public StatusPanel(Player player, Player opponent) {
        backImage = new ImageIcon(Graphics.PANEL_STATUS.getImage());
        image = backImage.getImage();
        setOpaque(false);
        initComponents(player, opponent);
    }

    public void initComponents(Player player, Player opponent) {
        statusBar = new JLabel();
        timer = new JLabel();

        add(getStatusBar());
        add(getTimer());

        update(player, opponent);
    }

    public JLabel getStatusBar() {
        return statusBar;
    }

    public JLabel getTimer() {
        return timer;
    }

    public void update(Player player, Player opponent) {
        StringBuilder status = new StringBuilder();

        status.append("<html>");

        if (player != null) {

            status.append("Gold : <font color='yellow'>");
            status.append(player.getGold());
            status.append("</font> | My Units : ");
            //status.append("</font> | My Units : <font color='green'>");
            status.append(player.getUnitsAlive());
            status.append("/");
            //status.append("</font>/<font color='orange'>");
            status.append(player.getUnitsAlive() + player.getUnitsDestroyed());
            status.append(" | ");
            //status.append("</font> | ");
        }

        if (opponent != null) {
            status.append("Opponent Units : ");
            //status.append("Opponent Units : <font color='green'>");
            status.append(opponent.getUnitsAlive());
            status.append("/");
            //status.append("</font>/<font color='orange'>");
            status.append(opponent.getUnitsAlive() + opponent.getUnitsDestroyed());
            status.append(" | ");
            //status.append("</font> | ");
        }

        status.append("</html>");

        getStatusBar().setText(status.toString());
        getStatusBar().setForeground(Color.WHITE);
        getTimer().setForeground(Color.WHITE);
    }

    @Override
    public void paintComponent(java.awt.Graphics g) {
        g.drawImage(image, 0, 0, this);
        super.paintComponent(g);
    }
}
